<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			/**
			 * @param {string} haystack
			 * @param {string} needle
			 * @return {number}
			 */
			//输入：haystack = "hello", needle = "ll"
			//输出：2
			//输入：haystack = "aaaaa", needle = "bba"
			//输出：-1
			//输入：haystack = "", needle = ""
			//输出：0
			var strStr = function(haystack, needle) {
			    const n = haystack.length, m = needle.length;
			    for (let i = 0; i + m <= n; i++) {
			        let f = true;
			        for (let j = 0; j < m; j++) {
			            if (haystack[i + j] != needle[j]) {
			                f = false;
			                break;
			            }
			        }
			        if (f) {
			            return i;
			        }
			    }
			    return -1;
			};
			console.log(strStr("hello","ll"));
		</script>
	</body>
</html>
